namespace Paperless.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class addNoteAgentRelation : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.Agents", "TransactionId", "dbo.Transactions");
            DropForeignKey("dbo.Notes", "TransactionId", "dbo.Transactions");
            DropIndex("dbo.Agents", new[] { "TransactionId" });
            DropIndex("dbo.Notes", new[] { "TransactionId" });
            CreateTable(
                "dbo.NoteAgents",
                c => new
                    {
                        Note_Id = c.Long(nullable: false),
                        Agent_Id = c.Long(nullable: false),
                    })
                .PrimaryKey(t => new { t.Note_Id, t.Agent_Id })
                .ForeignKey("dbo.Notes", t => t.Note_Id, cascadeDelete: true)
                .ForeignKey("dbo.Agents", t => t.Agent_Id, cascadeDelete: true)
                .Index(t => t.Note_Id)
                .Index(t => t.Agent_Id);
            
            AlterColumn("dbo.Agents", "TransactionId", c => c.Long());
            AlterColumn("dbo.Notes", "TransactionId", c => c.Long());
            CreateIndex("dbo.Agents", "TransactionId");
            CreateIndex("dbo.Notes", "TransactionId");
            AddForeignKey("dbo.Agents", "TransactionId", "dbo.Transactions", "Id");
            AddForeignKey("dbo.Notes", "TransactionId", "dbo.Transactions", "Id");
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Notes", "TransactionId", "dbo.Transactions");
            DropForeignKey("dbo.Agents", "TransactionId", "dbo.Transactions");
            DropForeignKey("dbo.NoteAgents", "Agent_Id", "dbo.Agents");
            DropForeignKey("dbo.NoteAgents", "Note_Id", "dbo.Notes");
            DropIndex("dbo.NoteAgents", new[] { "Agent_Id" });
            DropIndex("dbo.NoteAgents", new[] { "Note_Id" });
            DropIndex("dbo.Notes", new[] { "TransactionId" });
            DropIndex("dbo.Agents", new[] { "TransactionId" });
            AlterColumn("dbo.Notes", "TransactionId", c => c.Long(nullable: false));
            AlterColumn("dbo.Agents", "TransactionId", c => c.Long(nullable: false));
            DropTable("dbo.NoteAgents");
            CreateIndex("dbo.Notes", "TransactionId");
            CreateIndex("dbo.Agents", "TransactionId");
            AddForeignKey("dbo.Notes", "TransactionId", "dbo.Transactions", "Id", cascadeDelete: true);
            AddForeignKey("dbo.Agents", "TransactionId", "dbo.Transactions", "Id", cascadeDelete: true);
        }
    }
}
